package com.qf.smsplatform.search.mq;

import com.netflix.discovery.converters.Auto;
import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.model.StandardReport;
import com.qf.smsplatform.search.service.ElasticsearchService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class ReportUpdateListener {

    @Autowired
    private ElasticsearchService elasticsearchService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT)
    public void consume(StandardReport report, Channel channel, Message message) throws IOException {
        //1. 修改ES的日志
        elasticsearchService.updateLog(report);
        //2. 手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }
}
